package org.goldenmock.web.matchers;

import org.goldenmock.web.server.EasyHttpRequest;

import java.util.Enumeration;

/**
 * @author Robin Wagenaar
 * @author Arjen van Staalduinen
 */
public class HeadersContainMatcher extends EasyRequestMatcher {
    private final String expectedHeaderName;
    private final String expectedHeaderValue;

    public HeadersContainMatcher(String headerName, String headerValue) {
        this.expectedHeaderName = headerName;
        this.expectedHeaderValue = headerValue;
    }

    @Override
    public boolean matchesEasyRequest(EasyHttpRequest actual) {
        Enumeration values = actual.getHeaders(expectedHeaderName);
        while (values.hasMoreElements()) {
            Object nextElement = values.nextElement();
            if(nextElement instanceof String){
                return ((String)nextElement).contains(expectedHeaderValue);
            }
        }
        return false;
    }
}
